import axios from "@/utils/http";
//数据
const state = {
  //数据定义处
  chargeMsg:[],
  chargeMsgTotal:1,
  tradeInfo:null,
  tradeInfoOut:null,
  tradeInfoPay:null,
};

const getters = {
  //修饰后的数据获取方法
  getChargeMsg(state:any){
    return state.chargeMsg
  },
  getTradeMsg(state:any){
     if(state.tradeInfo&&state.tradeInfo.tradeInfoList){
      let list = JSON.parse(JSON.stringify(state.tradeInfo.tradeInfoList))
      console.log("list",list);
      
      state.tradeInfoPay = []
      state.tradeInfoOut = []
      if(list.length>0){
        list.forEach((item:any) => {
          if(item.payKind){
            state.tradeInfoOut.push(item)
          }else{
            state.tradeInfoPay.push(item)
          }
        });
      }
     }
    return {
      tradeInfo:state.tradeInfo,
      tradeInfoOut:state.tradeInfoOut,
      tradeInfoPay:state.tradeInfoPay,
    }
  }
};


const mutations = {
  //修改数据处 ，可在这写axios请求拿数据
  setChargeMsg(state:any,page:any){
    axios({
      url:"/diagnose/queryBaseMsg",
      method:"get",
      params:{
        currentPage:page.currentPage,
        pageSize:page.pageSize,
        keywords:page.keywords,
        status:page.status
      }
      }).then((res:any)=>{
        console.log("res",res);
        
          state.chargeMsg=res.data.data
          state.chargeMsgTotal=res.data.count
     }).catch(err=>{
      console.log(err);
     })
    
  },
  releseDrugById(state:any,id:any){
    axios({
      url:"/diagnose/releseDrug",
      method:"post",
      params:{
        diagnoseId:id
      }
      }).then((res:any)=>{
        // console.log("res",res);
     }).catch(err=>{
      console.log(err);
     })
  },
  //未做展示
  scriptBydiaId(state:any,id:any){
    console.log("id",id);
    axios({
      url:"/diagnose/queryScriptBydiaId",
      method:"get",
      params:{
        diagnoseId:id
      }
      }).then((res:any)=>{
        console.log("res",res);
        
          // state.chargeMsg=res.data.data
          // state.chargeMsgTotal=res.data.count
     }).catch(err=>{
      console.log(err);
     })
  },
  payMoneyById(state:any,msg:any){
    axios({
      url:"/alipay",
      method:"get",
      params:{
        message:msg.message,
      orderId:msg.orderId,
      price:msg.price,
      tradeType :msg.tradeType
      }
      }).then((res:any)=>{
        // res.data
     }).catch(err=>{
      console.log(err);
     })
  },
  returnMoneyById(state:any,msg:any){
    axios({
      url:"/refund",
      method:"post",
      params:{
        message:msg.message,
      orderId:msg.orderId,
      price:msg.price,
      tradeType :msg.tradeType
      }
      }).then((res:any)=>{
        console.log("refund",res);
     }).catch(err=>{
      console.log(err);
     })
  },
  showTradeInfo(state:any,row:any){
    axios({
      url:"/diagnose/showTradeInfoBySeeDoctorId",
      method:"get",
      params:{
        seeDoctorId:row.id,
      }
      }).then((res:any)=>{
        state.tradeInfo=res.data.data
     }).catch(err=>{
      console.log(err);
     })
  },
  showTradeInfoPay(state:any,row:any){
    axios({
      url:"/diagnose/showTradeInfoPay",
      method:"get",
      params:{
        diagnoseId:row.id,
      }
      }).then((res:any)=>{
        state.tradeInfoPay=res.data.data
     }).catch(err=>{
      console.log(err);
     })
  },
  showTradeInfoOut(state:any,row:any){
    axios({
      url:"/diagnose/showTradeInfoOut",
      method:"get",
      params:{
        diagnoseId:row.id,
      }
      }).then((res:any)=>{
        state.tradeInfoOut=res.data.data
     }).catch(err=>{
      console.log(err);
     })
  },
};

const actions = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
